import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_study/flutter/_14%E5%9B%BD%E9%99%85%E5%8C%96/i18n/text_localizations.dart';

class TextLocalizationDelegate extends LocalizationsDelegate<TextLocalization> {
  static TextLocalizationDelegate delegate = TextLocalizationDelegate();

  // 设置支持的语言
  @override
  bool isSupported(Locale locale) {
    return ['zh', 'en'].contains(locale.languageCode);
  }

  // Widget重新build，是否需要重新加载locale资源，一般情况不需要
  @override
  bool shouldReload(covariant LocalizationsDelegate<dynamic> old) {
    return false;
  }

  @override
  Future<TextLocalization> load(Locale locale) async {
    final localization = TextLocalization(locale);
    await localization.loadJson();
    return localization;
  }
}
